<!-- <?php
include_once("./Db_pdo.class.php");
// $DB=new Db_pdo("jmshop","root","root");
// $DB=new Db_pdo("cxh_v3_test","cxhv3","cxhv3pwd!@#");
$DB=new Db_pdo("cxh_v3","cxhv3","cxhv3pwd!@#");
echo '<pre>';
//计算 


$buying = unserialize(file_get_contents('buying.txt')); 
// print_r($buying);
// exit;
//车补是全部返款
foreach ($buying as $key => $value) {
	$param['id'] = $value['buying_id'];
	//车牌
	$param['aplc_car_no'] = $value['plate_number'];
	//vin
	$param['aplc_car_vin'] = $value['vin_number'];
	//车型
	$param['aplc_car_type'] = $value['car_model'];
	//状态
	$param['aplc_status'] = $value['buy_state'];
	//开始返款
	if($value['buy_state']==1){
		$param['is_all_back'] = 1;
		$param['is_month_back'] =1;
	}else{
		$param['is_all_back'] = 0;
		$param['is_month_back'] =0;
	}

	// if(!($value['total_points']>0)){
	// 	$param['is_all_back'] =0;
	// 	$param['is_month_back'] =0;

	// }
	
	$param['member_id'] = $value['user_id'];
	$param['ctime'] =$value['time'];
	

	//剩余返款金额
	$param['aplc_totel_balance'] = $value['no_points'];
	//已经返款天数
	if($value['total_points']&&$value['total_points']>0){
		$param['aplc_totel_retime']  =  ceil($value['back_points']/($value['total_points']*$value['ratio']));
	}
	
	//已返款积分
	$param['aplc_re_integral'] =0;

	 //判断按的比例来计算
	if($value['percent']==1){
		//现金返款比列 
		$param['aplc_re_money_p'] =0.8;
		//维护费比例
		$param['aplc_re_fee_p'] = 0.2;
		//已返款金额
		$param['aplc_re_money'] = round($value['back_points']*0.8,2);
		//平台维护费
		$param['aplc_re_fee'] = $value['back_points']-$param['aplc_re_money'];
	}else{
		//现金返款比列 
		$param['aplc_re_money_p']  =1;
		//维护费比例
		$param['aplc_re_fee_p'] =0;
		$param['aplc_re_fee'] = 0;
		$param['aplc_re_money'] = $value['back_points'];
	}
	//积分比列
	$param['aplc_re_integral_p'] =0;
	
	//总金额
	$param['aplc_totel_money'] =$value['total_points'];

	//每天返款金额
	$day_money =round($value['total_points']*$value['ratio'],2);
	if($day_money){
		//总返款天数
		$param['aplc_totel_days'] =ceil($value['total_points']/$day_money);
	}
	$param['aplc_actual_money'] = $value['buy_total'];
	
	
	$DB->table("ims_cxh_apply_subsidy_car")->insert($param);


}


//门票

$ticket = unserialize(file_get_contents('tickets.txt')); 

foreach ($ticket as $key1 => $value1) {
	$param1['id'] = $value1['id'];
	//总金额
	$param1['aplt_totel_money'] = $value1['total'];
	
	// //总返款天数
	$param1['aplt_totel_days'] = 2000;
	// 
	//剩余返款金额
	$param1['aplt_totel_balance'] = $value1['no_back'];
	

	//已返金额
	$param1['aplt_re_money'] = $value1['back'];
	
	//已返积分
	$param1['aplt_re_integral'] =0;
	
	//平台维护费总额
	$param1['aplt_re_fee'] =0;
	
	//现金返款比例
	$param1['aplt_re_money_p'] =1;
	
	//自定义返款名称
	$param1['aplt_name'] ='年会门票';
	
	//审核状态
	$param1['aplc_status'] = 1;
	
	//开始返款
	$param1['is_all_back'] =1;
	
	//月返款
	$param1['is_month_back'] =1;
	
	//
	$param1['member_id'] = $value1['user_id'];
	$DB->table("ims_cxh_apply_subsidy_things")->insert($param1);
	
	
	
}


$ticket_day = unserialize(file_get_contents('ticket_day.txt')); 
foreach ($ticket_day as $key2 => $value2) {
	// //已经返款天数
	$param2['aplt_totel_retime'] = $value2['num'];
	$DB->table("ims_cxh_apply_subsidy_things")->where("member_id=".$value2['user_id'])->update($param2);
}


//代理商运营

$agent_day= unserialize(file_get_contents('agent_day.txt')); 
// print_r($agent_day);
// exit;
foreach ($agent_day as $key3 => $value3) {
	$param3['id'] = $value3['back_id'];
	//总金额
	$param3['apla_totel_money'] =$value3['total_points'];
	//总共返款天数
	if($value3['ratio']){
		$param3['apla_totel_days'] = ceil(1/$value3['ratio']);

	}
	
	//剩余返款金额
	$param3['apla_totel_balance'] =$value3['no_points'];
	//已经返款天数
	$param3['apla_totel_retime']  =  ceil($value3['back_points']/($value3['total_points']*$value3['ratio']));
	// $param3['apla_totel_retime'] =ceil($value3['back_points']/$value3['ratio']);
	//已返款金额
	$param3['apla_re_money'] =$value3['back_points'];
	//现金返款比列
	$param3['apla_re_money_p'] =1;
	//店铺名称
	$param3['apla_shop'] =$value3['user_name'];
	// //店铺地址
	// $param3['apla_shop_addr'] =;
	//状态
	if($value3['back_state']==2){
		$param3['apla_status'] =2;
		$param3['is_all_back'] =0;
		$param3['is_month_back'] =0;

	}else if($value3['back_state']==1){
		$param3['apla_status'] =1;

		$param3['is_all_back'] =1;
		$param3['is_month_back'] =1;
	}else{
		$param3['apla_status'] =0;

		$param3['is_all_back'] =0;
		$param3['is_month_back'] =0;
	}
	$param3['member_id'] =$value3['user_id'];
	$param3['ctime'] =$value3['time'];
	$DB->table("ims_cxh_apply_subsidy_agent")->insert($param3);
	
	

	
}

//代理商返款天数
// $agent_cday= unserialize(file_get_contents('agent_cday.txt')); 

// foreach ($agent_cday as $key4 => $value4) {
// 	// 	// //已经返款天数
// 	$param4['apla_totel_retime'] = $value4['num'];
// 	$DB->table("ims_cxh_apply_subsidy_agent")->where("member_id=".$value4['user_id'])->update($param4);
// }

// print_r($agent_cday);

// print_r($ticket);


 -->